package com.example.controller;

import com.example.feign.AuthFeignClient;
import com.example.model.api.Result;
import com.example.model.api.ResultBuilder;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@RestController
@Hidden
@RequestMapping("/demo")
public class DemoController implements AuthFeignClient {
    @GetMapping
    @PreAuthorize("hasRole('ROLE_USER')")
    public String demo() {
        return "hello demo";
    }

    @PostMapping("/me")
    public Authentication who(Authentication authentication) {


        return authentication;
    }

    @GetMapping("hello")
    public Mono<String> gethello() {
        System.out.println("hello");

        return Mono.just("Hello, me!");
    }

    @GetMapping("userinfo")
    public Mono<String> getUserInfo() {



        return Mono.just("Hello, me!");
    }

    @GetMapping("openfignDemo")
    @Override
    public Result<String> openfignDemo(){

//        try{
//            Thread.sleep(100000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }

        return ResultBuilder.<String>aResult().data("ooookkkk").build();
    }


}
